package lsp12

import (
	"P1-f12/official/lsplog"
)

// iLspServer -- the struct that LspServer maintains:
// TODO
// should include at least:
// 1. a linked list of the buffer 
// 2. a map of key: clientAddr, value : iLspClient 
// 4.
//

type iLspServer struct {
}

// iNewLspServer -- setup and initiate the server
// Set up an application server on specified port.
// Call returns once server ready to accept connection requests
// parameter:
//     port     -- server's listening port number
//     params   -- pointer to a struct giving the LSP parameters,
//                 set it nil as default values
// return value: (returns after connection established, i.e. Ack msg received
//     LspServer -- the pointer to the established Server struct
//     error     -- non-nil if connection cannot be established

func iNewLspServer(port int, params *LspParams) (*LspServer, error) {
	return nil, lsplog.NotImplemented("iNewLspServer")
}


// Read next message received by server, return connection ID + contents
// Call blocks until value available to read, or network disconnected
// Return value:
//    the connection ID -- indicating the client from which the msg was received
//    the msg paylod
//    error --non-nil error when connection lost
// When connection ID > 0 & error non-nil, this indicates that the
// particular connection has terminated.
//
// When connection ID == 0 & error non-nil, then server is no longer
// operational
func (srv *LspServer) iRead() (uint16, []byte, error) {
	return 0, nil, lsplog.NotImplemented("iRead")
}


// Write message to specified client -- determined by connID
// Return immediately, non-nil error when client is no longer available 
// connID should be > 0
// Any attempt to send message with connID == 0
// will be ignored, with non-nil error value returned.
func (srv *LspServer) iWrite(connId uint16, payload []byte) error {
	return lsplog.NotImplemented("iWrite")
}

// Close only specified connection
// connID should be > 0.
// Call blocks unitl all pending message to the client have been sent, 
//              or network connection lost
// Calling close on already closed connection should be possible.
// Client should not attempt call to Read or Write after calling Close
func (srv *LspServer) iCloseConn(connId uint16) {
        return
}


// Close all connections and terminate server
// Calling closeAll should be possible even when there are no active connections.
// Once the call to Close has been completed, any goroutines associated with the server should exit
// Application should not attempt to call Read or Write after calling CloseAll
func (srv *LspServer) iCloseAll() {
	return
}

